"""
Author        yongfa
Date          2022-07-18 09:21:39
LastEditTime  2022-07-19 19:08:37
LastEditors   yongfa
Description   路由配置
"""
from flask_restx import Resource
from app.extensions.decorators import casbin_required
from .services import SystemLogService
from .parameters import get_list_params
from .models import SystemLog


def configure_router(ns):

    @ns.route('')
    class SystemLogListResource(Resource):
        """系统日志"""
        method_decorators = [casbin_required]

        @ns.doc(parser=get_list_params)
        def get(self):
            """获取系统日志"""
            return SystemLogService(model=SystemLog, args=get_list_params, is_desc=True).get_list()

    @ns.route('/<int:id>')
    @ns.doc(params={"id": "The Log ID"})
    class SystemLogResource(Resource):
        """系统日志详情"""
        method_decorators = [casbin_required]

        def get(self, id):
            """获取系统日志详情"""
            return SystemLogService(model=SystemLog).get_detail(id)

        def delete(self, id):
            """删除系统日志"""
            return SystemLogService(model=SystemLog).delete(id)
